function request(opion) {
    return new Promise((resolve, reject) => {
        const xmlhttp = new XMLHttpRequest()
        var res = null

        // xmlhttp.open('get', './static/audios/globalParams.json', true)

        let jsonSrc = '../src/message/' + opion.jsonSrc
        xmlhttp.open('get', jsonSrc, true)
            // xmlhttp.open('get', 'localhost:8089/package.txt', true)
        xmlhttp.send();
        // CustomEvent的polyfill
        (function() {
            if (typeof window.CustomEvent === 'function') return false

            function CustomEvent(event, params) {
                params = params || {
                    bubbles: false,
                    cancelable: false,
                    detail: undefined
                }
                var evt = document.createEvent('CustomEvent')
                evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail)
                return evt
            }
            CustomEvent.prototype = window.Event.prototype
            window.CustomEvent = CustomEvent
        })()
        xmlhttp.onreadystatechange = function() {
            if (xmlhttp.readyState === 4) {
                if (xmlhttp.status === 200) {
                    res = JSON.parse(xmlhttp.responseText) //
                    const e = new CustomEvent('ready')
                    document.dispatchEvent(e)
                    resolve(res)
                } else {
                    console.error(`未找到文件`)
                    reject(null)
                }
            }
        }
    })
}

export default request